package com.turing.usdtpay.mvp.presenter;

import android.app.Activity;

import com.google.gson.Gson;
import com.turing.usdtpay.entity.MoneyData;
import com.turing.usdtpay.entity.PropertyData;
import com.turing.usdtpay.http.ApiService;
import com.turing.usdtpay.http.ApiUrl;
import com.turing.usdtpay.http.callback.ApiCallback;
import com.turing.usdtpay.http.entity.ResponseDate;
import com.turing.usdtpay.mvp.contract.PropertyContract;

import java.util.HashMap;

/**
 * @作者：JAY
 * @创建时间：2019/11/6 11:45
 * @描述：
 **/
public class PropertyPresenter implements PropertyContract.Present {
    private PropertyContract.View mView;

    public PropertyPresenter(PropertyContract.View mView) {
        this.mView = mView;
    }

    @Override
    public void getInfo(Activity activity, int page, int page_num, final boolean fresh) {
        HashMap<String,String> map = new HashMap<>();
        map.put("page",page+"");
        map.put("page_num",page_num+"");
        ApiService.getInstance().postRequestWithCommmon(activity, ApiUrl.API_GET_ASSETS_LOG, map, new ApiCallback() {
            @Override
            public void onSuccess(int code, ResponseDate date) {
                if (date.getRet() == 1){
                    Gson gson = new Gson();
                    PropertyData data = gson.fromJson(date.getDate(), PropertyData.class);
                    mView.getSuccess(data,fresh);
                }else {
                    mView.onFail(date.getMsg());
                }
            }

            @Override
            public void onFailure(Throwable exception) {
                mView.onFail(exception.getMessage());
            }
        });
    }
}
